package com.poisonh.unifiedauth.utils;

import android.content.res.Resources;
import android.util.Base64;

/**
 * 像素转换
 * Created by PoisonH on 2016/6/21.
 */
public class Utils
{
    public static float dp2px(Resources resources, float dp)
    {
        final float scale = resources.getDisplayMetrics().density;
        return dp * scale + 0.5f;
    }

    public static float sp2px(Resources resources, float sp)
    {
        final float scale = resources.getDisplayMetrics().scaledDensity;
        return sp * scale;
    }

    public static byte[] decryptBASE64(String key) throws Exception
    {
        return Base64.decode(key, Base64.DEFAULT);
    }

    public static String encryptBASE64(byte[] key) throws Exception
    {
        return Base64.encodeToString(key, Base64.DEFAULT);
    }
}
